module.exports = {
  /**
   * 获取招商邀请码列表
   * @url user/kh/getUserList 前端调用的url参数地址
   */
	main: async (event) => {
		let { data = {},userInfo,  util, originalParam } = event;
		let { uniID, pubFun, vk , db, _ } = util;
		let res = {code : -1, msg : ''};
	  // 业务逻辑开始----------------------------------------------------------- 
		// 可写与数据库的交互逻辑等等
		let {pageNum, pageSize, sign_name, todayStart, todayEnd} = data;
		// 仅限以下表允许不登录查看
		let dbName = "vk-orders";
		let whereJson = {};
		let sortArr = [];
		// 指定返回字段开始-----------------------------------------------------------
		// 指定返回字段开始-----------------------------------------------------------
		// 排序规则开始-----------------------------------------------------------
		sortArr.push({
			"name":"_add_time",
			"type":"desc"
		});
    if (sign_name) {
    	whereJson['sign_name'] = new RegExp(`${sign_name}`)
    }
    const dbCmd = db.command
    if (todayStart && todayEnd) {
      whereJson["_add_time"] = dbCmd.gte(todayStart).and(dbCmd.lte(todayEnd))
    } else {
      
      if (todayStart) {
        whereJson["_add_time"] = dbCmd.gte(todayStart)
      }
      if (todayEnd) {
        whereJson["_add_time"] =dbCmd.lte(todayEnd)
      }
    }
		// 查询条件结束-----------------------------------------------------------
		res = await vk.baseDao.select({
			dbName:dbName,
			pageKey:true,
			getCount: true,
			pageIndex:pageNum || 1,
			pageSize:pageSize || 100,
			whereJson:whereJson,
			sortArr:sortArr
		}, util);
	  // 业务逻辑结束-----------------------------------------------------------
	  return res;
	}

}
